package gamebackend;

import generators.AbstractRandomGenerator;
import gui.BlockStyle;

import framework.Color;
import java.util.Random;

public class BigStarGenerator extends AbstractRandomGenerator {

	public BigStarGenerator(Random the_random,
			double the_chance) {
		super(new Block(BlockStyle.PLAIN, new Color(0, 0, 0)), the_random, the_chance);
	}

	@Override
	public void generate(Block[][] blocks) {
		if (getRandom().nextDouble() < getChance()) {
			getBlock().setColor(Block.getRandomColor(getRandom(), 600, 100));
			final int col = getRandom().nextInt(blocks[0].length);
			if (getRandom().nextInt(2) == 0) {
				place(blocks, 0, col);
				place(blocks, 1, col);
				place(blocks, 0, col + 1);
				place(blocks, 1, col + 1);
			} else {
				place(blocks, 1, col + 2);
				place(blocks, 1, col);
				place(blocks, 0, col + 1);
				place(blocks, 2, col + 1);
				place(blocks, 1, col + 1);
			}
		}
		
	}

	private void place(final Block[][] blocks, final int the_row, final int the_col) {
		if (the_col >= 0 && the_col < blocks[0].length) {
			blocks[the_row][the_col] = getBlock();
		}
	}

}
